package baseTest;

public class rob {
    public static void main(String[] args) {
        int[] nums = {2,1,1,2};
        System.out.println(process(nums,0));
    }
    public static int process(int[] nums,int i) {
       if (i >= nums.length){
           return 0;
       }
       return Math.max(process(nums,i+1),nums[i]+process(nums,i+2));
    }
    public static int process2(int[] nums){
        if ( nums.length<2){
            return nums[0];
        }
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        dp[1] = Math.max(dp[0],dp[1]);
        for (int i = 2; i < nums.length; i++) {
            dp[i] = Math.max(nums[i]+dp[i-2],dp[i-1]);
        }
        return dp[nums.length-1];
    }
}
